﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


public static class ObjectExt
{

    public static Dictionary<string, string> GetDictEnums(this Enum em, bool underlyingInt = false)
    {
        Dictionary<string, string> dict = new Dictionary<string, string>();
        Type tyEnum = em.GetType();
        foreach (string str in tyEnum.GetEnumNames())
        {
            dict.Add(str, str);
            if (underlyingInt)
            {
                dict[str] = Convert.ToInt32(Enum.Parse(tyEnum, str)).ToString();
            }
        }
        return dict;
    }

    public static List<string> GetListEnums(this Enum em, bool underlyingInt = false)
    {
        List<string> lstEnums = new List<string>();
        Type tyEnum = em.GetType();
        foreach (string str in tyEnum.GetEnumNames())
        {
            string item = str;
            if (underlyingInt)
            {
                item = Convert.ToInt32(Enum.Parse(tyEnum, str)).ToString();
            }
            lstEnums.Add(item);
        }
        return lstEnums;
    }

    public static string ToUpperFirstword(this string value)
    {
        if (string.IsNullOrEmpty(value))
            return string.Empty;

        string result = string.Empty;
        string[] words = value.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
        if (value.Length <= 1)
        {
            return value.ToUpper();
        }
        else if (words.Length <= 1)
        {
            result = value.Substring(0, 1).ToUpper() + value.Substring(1, value.Length - 1).ToLower();
        }
        else
        {
            List<string> lst = new List<string>();
            foreach (string word in words)
            {
                if (!string.IsNullOrEmpty(word))
                {
                    string temp = word.Substring(0, 1).ToUpper() + word.Substring(1, word.Length - 1).ToLower();
                    lst.Add(temp);
                }
            }
            result = string.Join("_", lst);
        }
        return result;
    }
}

